layui.use(['form', 'layer', 'laydate', 'table', 'laytpl'], function () {
	var form = layui.form,
		$ = layui.jquery,
		laydate = layui.laydate,
		laytpl = layui.laytpl,
		table = layui.table,
		element = layui.element;

	//修改权限
	form.on("submit(ChangePower)", function (data) {
		var index = layer.msg('提交中，请稍候', {
			icon: 16,
			time: false,
			shade: 0.8
		});
		
		if (data.field.power) {
			if (data.field.power == '管理员') {
				var gid = 1
				var status=0
			} else if (data.field.power == '学生') {
				var gid = 2
				var status=0
			} else if (data.field.power == '老师') {
				var gid = 3
				var status=0
			}else if (data.field.power == '禁用') {
				var gid = 4
				var status=1
			}
			$.ajax({
				type: "post",
				url: "http://127.0.0.1:8000/roleChange",
				data: { "id": $(".id").val(), "gid": gid,"status":status},
				async: true,
				success: function (res) {
					// layer.alert(res.msg);
					// layer.close(index);
					setTimeout(function () {

						layer.msg(res.msg);
						layer.close(index);
						parent.location.reload();
					}, 1000);

				}
			});

			return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。

		}

	});

})
